AC_DEFUN([_PKG_CHECK_MODULE_VERSION],[dnl
m4_if(m4_index([$2], [>=]),[-1],[
        pkg_mod=$2
        AC_MSG_CHECKING([whether package $2 is present])
        PKG_CHECK_EXISTS([$2], [AC_MSG_RESULT([found])],
           [AC_MSG_RESULT([not found])
            AC_MSG_ERROR([Package $pkg_mod is required.])])
],[
        pkg_mod=m4_substr([$2], 0, m4_index([$2], [>=]))
        pkg_ver=m4_substr([$2], m4_eval(m4_index([$2], [>=]) + 2))
        AC_MSG_CHECKING([for package $pkg_mod version $pkg_ver])
        if $PKG_CONFIG --exists $pkg_mod; then
          real_ver=`$PKG_CONFIG --modversion $pkg_mod`
	  AC_MSG_RESULT([$real_ver])
	  if ! $PKG_CONFIG --atleast-version=$pkg_ver $pkg_mod; then
	    AC_MSG_ERROR([Package $pkg_mod version at least $pkg_ver is required.])
          fi
        else
          AC_MSG_RESULT([not found])
          AC_MSG_ERROR([Package $pkg_mod is required.])
        fi
  ])
m4_pattern_allow([$1_LDFLAGS])
m4_pattern_allow([$1_CPPFLAGS])
m4_pattern_allow([$1_LDADD])
m4_pattern_allow([$1_VALAFLAGS])
$1_CPPFLAGS="$$1_CPPFLAGS `$PKG_CONFIG --cflags $pkg_mod 2>/dev/null`"
$1_LDFLAGS="$$1_LDFLAGS `$PKG_CONFIG --libs-only-L $pkg_mod 2>/dev/null`"
$1_LDADD="$$1_LDADD `$PKG_CONFIG --libs-only-l $pkg_mod 2>/dev/null`"
$1_VALAFLAGS="$$1_VALAFLAGS --pkg=$pkg_mod"
AC_SUBST([$1_LDFLAGS])
AC_SUBST([$1_CPPFLAGS])
AC_SUBST([$1_LDADD])
AC_SUBST([$1_VALAFLAGS])
])

AC_DEFUN([PKG_CHECK_MODULES_VERSION],[dnl
  AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  m4_map_args_w([$2], [_PKG_CHECK_MODULE_VERSION([$1],], [)])
])
